package com.contexticon.mediaTest;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
 
public class PlayerFrame {
 
    private final JFrame frame;
    private final JPanel contentPane;
    private final JButton myButton;
 
    private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
 
    public static void main(String[] args) {
    	
    	System.setProperty("jna.library.path", "/Applications/VLC.app/Contents/MacOS/lib/");
 
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new PlayerFrame();
            }
        });
    }
 
    public PlayerFrame() {
        contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());
        contentPane.setBackground(Color.black);
 
        mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);
        
        myButton = new JButton("Play");
        myButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				start("/Users/dglodzik/Movies/FrontRoll.flv");
			}
		});
		
        contentPane.add(myButton, BorderLayout.SOUTH);       
        
 
        frame = new JFrame("Layout Example");
        frame.setAlwaysOnTop(true);
        frame.setLocation(100, 100);
        frame.setSize(600, 400);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(contentPane);
 
        frame.setVisible(true);
    }
 
    public long getCurrentTime() {	
    	return mediaPlayerComponent.getMediaPlayer().getTime();
    }
    
    private void start(String mrl) {
        mediaPlayerComponent.getMediaPlayer().playMedia(mrl);
    }
}